package com.yunhai.ucenter.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.model.entity.ums.UmsRole;
import com.yunhai.ucenter.service.SysRoleService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author mengze
 * @since 2023-08-23
 */
@RestController
@RequestMapping("/sysRole")
public class SysRoleController {

    @Resource
    private SysRoleService sysRoleService;

    @PostMapping("")
    public Ret addRole(@RequestBody UmsRole sysRole) throws Exception {
        sysRoleService.addRole(sysRole);
        return Ret.ok();
    }

    @PutMapping("")
    public Ret updateRole(@RequestBody UmsRole sysRole) throws Exception {

        sysRoleService.updateRole(sysRole);
        return Ret.ok();
    }

    @PostMapping("/batchRemove")
    public Ret batchRemoveRole( @RequestBody List<Long> ids ) throws Exception {

        sysRoleService.batchRemoveRole(ids);
        return Ret.ok();
    }

    @GetMapping("/pagination")
    public Ret paginationRoleList( PaginationVo paginationVo ) throws Exception {

        IPage page = sysRoleService.paginationRoleList(paginationVo);
        return Ret.toPage(page);
    }

    @GetMapping("/list")
    public Ret allRoleList() throws Exception {

        List<UmsRole> sysRoles = sysRoleService.allRoleList();
        return Ret.ok(sysRoles);
    }
}

